package com.ds.infrastructure.audit.admin.controller;

import com.ds.infrastructure.audit.admin.service.IAdminService;
import com.ds.infrastructure.audit.admin.vo.DefaultResponseVO;
import com.ds.infrastructure.audit.admin.vo.KbaBehaviorVO;
import com.ds.infrastructure.audit.common.entity.Pager;
import com.ds.infrastructure.audit.common.entity.Result;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.RolesAllowed;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * 作用：
 *
 * @author WeiShaoying
 * @date 2020/7/31
 */
@RestController
@RequestMapping(value = "/admin")
@Slf4j
public class AdminController {

    @Resource
    private IAdminService adminService;

    @ApiOperation(value = "Search Key Behavior")
    @PostMapping(value = "/search")
    public Result searchBehavior(@RequestBody KbaBehaviorVO vo) {
        log.info(vo.toString());
        DefaultResponseVO responseVO = adminService.searchBehavior(vo);
        if (responseVO != null && responseVO.getStatus() == 1) {
            List<Object> list = Collections.singletonList(responseVO.getData());
            return Result.success(new Pager<>(responseVO.getTotal(), list));
        } else {
            return Result.success();
        }
    }

}
